import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {UsersService} from '../../providers/users.service';
import { Storage } from '@ionic/storage';
/**
 * Generated class for the PersonalUserDonePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-personal-user-done',
  templateUrl: 'personal-user-done.html',
  providers:[UsersService]
})
export class PersonalUserDonePage {
  houses;
  noMore:boolean = false;
  user;
  status:number;

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private userSer:UsersService,
    private storage:Storage,
  ) {
  }

  trackByHouses(index: number, house: any): number { return house.houseId; }
  ionViewDidLoad() {
    let that = this;

    that.storage.ready().then(() =>{
      that.storage.get('user').then((user) =>{
        console.log(user);
        that.user = user;
        that.userSer.getMyRecord(user,function (result) {
          that.houses = result;
          if(result.length < 1){
            that.noMore = true;
          }
          console.log(result);
        });
      });

    })

  }





//按照arangeId删除
  delRecordByarrId(arrangeId){
    let that = this;
    let user = that.storage.get('user');
    that.userSer.delRecordByarrId({"arrangeId":arrangeId},function (result) {
      if(result.stateCode == 45){
        that.userSer.getMyRecord({"userId":that.user.userId,"token":that.user.token},function (result) {
          that.houses = result;

          console.log(result);
        })
      }else{
        console.log("删除看房信息失败");
      }

    })


  }

  //下拉刷新
  doRefresh(refresher) {
    console.log('Begin async operation', refresher);

    setTimeout(() => {
      this.userSer.getMyRecord(this.user,function (result) {
        this.houses = result;
        console.log(result);
      });
      refresher.complete();
    }, 2000);
  }

}
